<?php

require_once("lib/autoload.php");

header('Content-type: application/json');

$term = $_GET["term"];

if (!isset($term)) {
    $term = "";
}

$dc = new DataController();
$dc->connect();
$tags = $dc->getTagNames($term);
$dc->disconnect();   
   

$callback = $_GET["callback"];

if (isset($callback)) {
    print "$callback(";
}
print "[";

$size = count($tags);
$i = 1;
foreach($tags as $tag) {
    print "\"$tag\"";
    if ($i != $size) {
        print ",\n";
    }
    $i++;
}

print "]";
if (isset($callback)) {
    print ")";
}

?>